package com.haima.ziliao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haima.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PJiajiaoDetail;
import com.haima.ziliao.service.IPJiajiaoDetailService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 教师详情Controller
 * 
 * @author hima
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/ziliao/jiajiaodetail")
public class PJiajiaoDetailController extends BaseController
{
    @Autowired
    private IPJiajiaoDetailService pJiajiaoDetailService;

    /**
     * 查询教师详情列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(PJiajiaoDetail pJiajiaoDetail)
    {
        startPage();
        List<PJiajiaoDetail> list = pJiajiaoDetailService.selectPJiajiaoDetailList(pJiajiaoDetail);
        return getDataTable(list);
    }


    @GetMapping("/getList")
    public AjaxResult getList(PJiajiaoDetail pJiajiaoDetail)
    {
        List<PJiajiaoDetail> list = pJiajiaoDetailService.selectPJiajiaoDetailList(pJiajiaoDetail);
        return AjaxResult.success(list);
    }


    @GetMapping("/addDetail")
    public AjaxResult addDetail(PJiajiaoDetail pJiajiaoDetail)
    {
        pJiajiaoDetail.setUid(SecurityUtils.getUserId());
        pJiajiaoDetailService.insertPJiajiaoDetail(pJiajiaoDetail);
        return AjaxResult.success();
    }

    @GetMapping("/editDetail")
    public AjaxResult editDetail(PJiajiaoDetail pJiajiaoDetail)
    {
        PJiajiaoDetail detail = pJiajiaoDetailService.getById(pJiajiaoDetail.getId());
        detail.setNr(pJiajiaoDetail.getNr());
        detail.setType(pJiajiaoDetail.getType());
        pJiajiaoDetailService.updatePJiajiaoDetail(detail);
        return AjaxResult.success();
    }

    @GetMapping("/delDetail")
    public AjaxResult delDetail(PJiajiaoDetail pJiajiaoDetail)
    {
        pJiajiaoDetailService.deletePJiajiaoDetailById(pJiajiaoDetail.getId());
        return AjaxResult.success();
    }


    /**
     * 导出教师详情列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:export')")
    @Log(title = "教师详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PJiajiaoDetail pJiajiaoDetail)
    {
        List<PJiajiaoDetail> list = pJiajiaoDetailService.selectPJiajiaoDetailList(pJiajiaoDetail);
        ExcelUtil<PJiajiaoDetail> util = new ExcelUtil<PJiajiaoDetail>(PJiajiaoDetail.class);
        util.exportExcel(response, list, "教师详情数据");
    }

    /**
     * 获取教师详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pJiajiaoDetailService.selectPJiajiaoDetailById(id));
    }

    /**
     * 新增教师详情
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:add')")
    @Log(title = "教师详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PJiajiaoDetail pJiajiaoDetail)
    {
        return toAjax(pJiajiaoDetailService.insertPJiajiaoDetail(pJiajiaoDetail));
    }

    /**
     * 修改教师详情
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:edit')")
    @Log(title = "教师详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PJiajiaoDetail pJiajiaoDetail)
    {
        return toAjax(pJiajiaoDetailService.updatePJiajiaoDetail(pJiajiaoDetail));
    }

    /**
     * 删除教师详情
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiaodetail:remove')")
    @Log(title = "教师详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pJiajiaoDetailService.deletePJiajiaoDetailByIds(ids));
    }
}
